import Vue from "vue";
import VueRouter from "vue-router";

// 导入登录注册组件
import Reg from "../views/Reg/Reg.vue";
import Login from "../views/Login/Login.vue";
import Main from "../views/Main/Main.vue";
import Home from "../views/Menus/Home/Home.vue";
import Userinfo from "../views/Menus/User/UserInfo.vue";
import UserAvatar from "../views/Menus/User/UserAvatar.vue";
import UserPwd from "../views/Menus/User/UserPwd.vue";

Vue.use(VueRouter);

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push;

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

// 定义路由规则
const routes = [
  //注册路由
  { path: "/reg", name: "reg", component: Reg },
  //登录路由
  { path: "/login", name: "login", component: Login },
  {
    path: "/",
    name: "main",
    component: Main,
    redirect: "/home",
    children: [
      //  二级标签 路径不用写/
      { path: "home", name: "Home", component: Home },
      { path: "user-info", name: "Userinfo", component: Userinfo },
      { path: "user-avatar", name: "UserAvatar", component: UserAvatar },
      { path: "user-pwd", name: "UserPwd", component: UserPwd },
    ],
  },
];
// 创建路由实例对象
const router = new VueRouter({
  routes,
});
// 暴露路由对象
export default router;
